home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CPPTASK.ARJ / TSKSUB.CPP < prev    next >
C/C++ Source or Header  |  1991-08-21  |  2KB  |  94 lines

  1. /*
  2.    CPPTask - A Multitasking Kernel For C++
  3.  
  4.    Version 1.0 08-12-91
  5.  
  6.    Ported by Rich Smith from:
  7.  
  8.    Public Domain Software written by
  9.       Thomas Wagner
  10.       Patschkauer Weg 31
  11.       D-1000 Berlin 33
  12.       West Germany
  13.  
  14.    TSKSUB.CPP - CTask Support Subroutines
  15.  
  16.    Subroutines:
  17.         t_delay
  18.         killretn
  19.         tsk_kill_queue
  20.         tsk_timeout
  21. */
  22.  
  23. #include <stdio.h>
  24.  
  25. #include "task.hpp"
  26. #include "tsklocal.hpp"
  27.  
  28. /*
  29.    t_delay
  30.       delay the current task by "ticks" clock ticks.
  31.       If ticks is zero, the task is stopped.
  32. */
  33.  
  34. int far t_delay (dword ticks)
  35. {
  36.    tsk_cli();
  37.    tsk_current->queue = NULL;
  38.    if (ticks)
  39.       {
  40.       tsk_current->state = ST_DELAYED;
  41.       tsk_current->tsk_enqtimer (ticks);
  42.       }
  43.    else
  44.       tsk_current->state = ST_STOPPED;
  45.  
  46.    tasker.schedule ();
  47.    return (int)tsk_current->retptr;
  48. }
  49.  
  50.  
  51. /*
  52.    Killretn kills the current active task. It is used internally, but
  53.    can also be called from outside.
  54. */
  55.  
  56. void far killretn (void)
  57. {
  58.    tsk_cli ();
  59.    tsk_current->tsk_kill ();
  60.    tsk_current = NULL;
  61.    tasker.schedule ();
  62. }
  63.  
  64. /*
  65.    tsk_kill_queue
  66.       Removes all tasks from a queue. For internal use only, critical
  67.       section assumed entered.
  68. */
  69. void far tsk_kill_queue (tqueptr que)
  70. {
  71.    tcbptr curr;
  72.  
  73.    for (curr = *que; curr != NULL; curr = curr->get_next())
  74.       {
  75.       curr->tsk_unqtimer ();
  76.       curr->tsk_kill ();
  77.       }
  78.    *que = NULL;
  79. }
  80.  
  81.  
  82. #if (CLOCK_MSEC)
  83.  
  84. dword tsk_timeout (dword tout)
  85. {
  86.    dword t;
  87.  
  88.    t = (dword) (((double)tout / tick_factor) + 0.5);
  89.    return (t) ? t : 1; 
  90. }
  91.  
  92. #endif
  93.  
  94.